package actions;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import model.StudentDBModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import data.StudentData;

public class SubmitApplication extends Action {
	
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		StudentData studentData = (StudentData) request.getSession().getAttribute("studentData");
		
		StudentDBModel db = new StudentDBModel();
		
		String user = request.getRemoteUser();
		System.err.println("Remote User: " + user);
		
		String appID = db.addApplication(studentData, user);
		request.setAttribute("appID", appID);
		
		Vector<String> formData = studentData.getFormData();
		
		request.getSession().setAttribute("formData", formData);
		request.getSession().setAttribute("studentData", studentData);
		
		return mapping.findForward("success");
	}

}
